//
//  ClassListViewController.m
//  YanMusicPlayer
//
//  Created by 1564335 on 15-6-19.
//  Copyright (c) 2015年 胡岩 All rights reserved.
//

#import "ClassListViewController.h"
#import "SingerMusicListModel.h"
#import "Tag_typeModel.h"
#import "ClassListTableViewCell.h"
#import "RankMusicList.h"


@interface ClassListViewController ()<HeaderViewSize, UITableViewDataSource, UITableViewDelegate, sendSingerTouch>

@property(nonatomic, strong) UIView *backgroundView;
@property(nonatomic, strong) UIView *singerListView;
@property(nonatomic, strong) HearderView *hearderView;
@property(nonatomic, strong) UIActivityIndicatorView *activity;
@property(nonatomic, strong) UIView *selectView;


@property(nonatomic, strong) UILabel *titleLabel;

@property(nonatomic, assign) CGFloat currentX;

@property(nonatomic, assign) CGFloat currentY;

@property(nonatomic, assign) CGFloat totalDistance;


@property(nonatomic, assign) CGFloat startY;

@property(nonatomic, assign) NSInteger theTime;

@property(nonatomic, strong) NSMutableArray *urlArray;

@property(nonatomic, strong) Tag_typeModel *tab_typeModel;

@property(nonatomic, strong) UITableView *classListTableView;

@property(nonatomic, strong) NSMutableArray *arrayData;

@property(nonatomic, strong) NSMutableArray *imageArray;

@property(nonatomic, assign) NSInteger imageNumber;

@property(nonatomic, strong) UIButton *button;

@property(nonatomic, strong) UITableView *catalogTableView;

@property(nonatomic, assign) BOOL isLoaded;

@end

@implementation ClassListViewController

- (void)sendBegin
{
    [UIView animateWithDuration:0.8 animations:^{
        _catalogTableView.frame = CGRectMake(-120, 30, 120, _HEIGHT - 94);
        _button.frame = CGRectMake(10, _HEIGHT - 130 * (_HEIGHT / _DEFAULT_HEIGHT), 40, 40);
    }];
    [UIView animateWithDuration:0.8 animations:^{
        self.singerListView.frame = CGRectMake(-(_WIDTH - 20), 150 * (_HEIGHT / _DEFAULT_HEIGHT), _WIDTH - 20, _HEIGHT - 300 * (_HEIGHT / _DEFAULT_HEIGHT));
    }];
    _startY = (int)_hearderView.frame.origin.y;
}
- (void)sendHeaderViewSize:(CGFloat)height
{
    _totalDistance += height;
    _currentY = height;
    if ((int)(_hearderView.frame.origin.y + height) < (int)_HEIGHT - 64 * (_HEIGHT / _DEFAULT_HEIGHT) && (int)(_hearderView.frame.origin.y + height) > (int)(74 * (_HEIGHT / _DEFAULT_HEIGHT))) {
        _hearderView.center = CGPointMake(_hearderView.center.x, _hearderView.center.y + height);
        if (_totalDistance > 0 && (int)_startY != (int)(_HEIGHT - 64 * (_HEIGHT / _DEFAULT_HEIGHT))) {
            
            [HearderView shareInstance].isList = NO;
            [UIView animateWithDuration:0.8 animations:^{
                [HearderView shareInstance].listTableView.alpha = 0.0f;
                [HearderView shareInstance].titleImageView.alpha = 1.0f;
            }];
            
            _backgroundView.alpha = 0.7 - 0.7 * (_totalDistance / (_HEIGHT - 64 * (_HEIGHT / _DEFAULT_HEIGHT)));
        } else if ((int)_totalDistance > (int)(-(_HEIGHT - 64 * (_HEIGHT / _DEFAULT_HEIGHT))) && (int)_startY != (int)(74 * (_HEIGHT / _DEFAULT_HEIGHT))) {
            _backgroundView.alpha = 0.7 * (-_totalDistance / (_HEIGHT - 64 * (_HEIGHT / _DEFAULT_HEIGHT)));
        }
    }
    [self.view bringSubviewToFront:_hearderView];
}

- (void)sendOver
{
    if (_theTime == 0 && (int)_startY == (int)(_HEIGHT - 64 * (_HEIGHT / _DEFAULT_HEIGHT)) && _totalDistance < 0) {
        _backgroundView.userInteractionEnabled = NO;
        _theTime = 1;
    } else if (_theTime == 1 && (int)_startY == (int)(74 * (_HEIGHT / _DEFAULT_HEIGHT)) && _totalDistance > 0) {
        _backgroundView.userInteractionEnabled = YES;
        _theTime = 0;
    }
    if (_currentY > 0) {
        [UIView animateWithDuration:0.8 animations:^{
            _hearderView.frame = CGRectMake(0, _HEIGHT - 64 * (_HEIGHT / _DEFAULT_HEIGHT), _WIDTH, _HEIGHT);
            self.backgroundView.alpha = 0.0;
        }];
    } else if (_currentY <= 0) {
        [UIView animateWithDuration:0.8 animations:^{
            _hearderView.frame = CGRectMake(0, 74 * (_HEIGHT / _DEFAULT_HEIGHT), _WIDTH, _HEIGHT);
            self.backgroundView.alpha = 0.7;
        }];
    }
    [self.view bringSubviewToFront:_hearderView];
    _totalDistance = 0;
    _currentY = 0;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _isLoaded = NO;
    UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _WIDTH, _HEIGHT)];
    [self.view addSubview:backgroundImageView];
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *backgroundView = [[UIVisualEffectView alloc] initWithEffect:effect];
    backgroundView.frame = CGRectMake(0, 0, _WIDTH, _HEIGHT);
    [self.view addSubview:backgroundView];
    [backgroundImageView setImage:[UIImage imageNamed:@"bgImage2"]];
    
    // 初始化背景
    _backgroundView = [[UIView alloc] initWithFrame:self.view.frame];
    _backgroundView.backgroundColor = [UIColor blackColor];
    _backgroundView.alpha = 0.0;
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
    [_backgroundView addGestureRecognizer:tap];
    [self.view addSubview:_backgroundView];
    
    _hearderView = [HearderView shareInstance];
    _hearderView.frame = CGRectMake(0, _HEIGHT - 64 * (_HEIGHT / _DEFAULT_HEIGHT), _WIDTH, _HEIGHT);
    [self.view addSubview:_hearderView];
    _hearderView.HeaderViewDelegate = self;
    [self.view bringSubviewToFront:_hearderView];
    
    // 歌手列表
    self.singerListView = [[UIView alloc] initWithFrame:CGRectMake(-(_WIDTH - 20), 150 * (_HEIGHT / _DEFAULT_HEIGHT), _WIDTH - 20, _HEIGHT - 300 * (_HEIGHT / _DEFAULT_HEIGHT))];
    self.singerListView.layer.cornerRadius = 5;
    self.singerListView.layer.masksToBounds = YES;
    [self.view addSubview:self.singerListView];
    self.singerListView.backgroundColor = [UIColor colorWithRed:211/255.0 green:218/255.0 blue:252/255.0 alpha:1];
    
    
    [self.view bringSubviewToFront:_backgroundView];
    [self.view bringSubviewToFront:_singerListView];
    [self.view bringSubviewToFront:_hearderView];
    
    _activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [self.view addSubview:_activity];
    [_activity startAnimating];
    _activity.center = self.view.center;
    [self loadImage];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 30 * (_HEIGHT / _DEFAULT_HEIGHT), _WIDTH, 40 * (_HEIGHT / _DEFAULT_HEIGHT))];
    titleLabel.text = @"分  类";
    titleLabel.font = [UIFont systemFontOfSize:28 * (_HEIGHT / _DEFAULT_HEIGHT)];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:titleLabel];
    
    _button = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:_button];
    [_button addTarget:self action:@selector(showCatalog:) forControlEvents:UIControlEventTouchUpInside];
    _button.frame = CGRectMake(10, _HEIGHT - 130 * (_HEIGHT / _DEFAULT_HEIGHT), 40, 40);
    _button.layer.cornerRadius = 20;
    _button.layer.masksToBounds = YES;
    [_button setImage:[UIImage imageNamed:@"iconfont-find"] forState:UIControlStateNormal];
    
    
    
    
}

- (void)showCatalog:(UIButton *)button
{
    [[CDSideBarController sharedInstance] dismissMenu];
    if (_isLoaded) {
        [self.view bringSubviewToFront:_backgroundView];
        [self.view bringSubviewToFront:_catalogTableView];
        [self.view bringSubviewToFront:_hearderView];
        [UIView animateWithDuration:0.8 animations:^{
            _catalogTableView.frame = CGRectMake(0, 30, 120, _HEIGHT - 94);
            _backgroundView.alpha = 0.7;
            _button.frame = CGRectMake(10, _HEIGHT - 64 * (_HEIGHT / _DEFAULT_HEIGHT), 40, 40);
        }];
    }
}

- (void)loadImage
{
    NSString *path = [URLPath ClassAnotherURL];
    _imageArray = [NSMutableArray array];
    path = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager GET:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:operation.responseData options:NSJSONReadingMutableContainers error:nil];
        NSArray *array = dic[@"data"];
        for (NSDictionary *dic in array) {
            NSString *pic_url_240_200 = dic[@"pic_url_240_200"];
            [_imageArray addObject:pic_url_240_200];
        }
        [self netWork];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"网络连接失败!" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        
    }];

}

- (void)netWork
{
    NSString *path = [URLPath ClassMainURL];
    _arrayData = [NSMutableArray array];
    path = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager GET:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:operation.responseData options:NSJSONReadingMutableContainers error:nil];
        NSArray *array = dic[@"data"];
        for (NSDictionary *dic in array) {
            _tab_typeModel = [[Tag_typeModel alloc] initWithDic:dic];
            [self.arrayData addObject:_tab_typeModel];
        }
        [_activity stopAnimating];
        [self initMainView];
        _isLoaded = YES;
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [_activity stopAnimating];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"网络连接失败!" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        
    }];
}



- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [HearderView shareInstance].isSongListView = NO;
    [HearderView shareInstance].title.alpha = 0;
    _backgroundView.alpha = 0.0;
    _hearderView = [HearderView shareInstance];
    _hearderView.frame = CGRectMake(0, _HEIGHT - 64 * (_HEIGHT / _DEFAULT_HEIGHT), _WIDTH, _HEIGHT);
    [self.view addSubview:_hearderView];
    _hearderView.HeaderViewDelegate = self;
    [self.view bringSubviewToFront:_hearderView];
    [HearderView shareInstance].titleImageView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1);
    [HearderView shareInstance].titleImageView.center = CGPointMake(37 * (_WIDTH / _DEFAULT_WIDTH), 32 * (_HEIGHT / _DEFAULT_HEIGHT));
    
    [HearderView shareInstance].lastButton.frame = CGRectMake(_WIDTH - 240 * (_WIDTH / _DEFAULT_WIDTH), 15, 30 * (_WIDTH / _DEFAULT_WIDTH), 30 * (_HEIGHT / _DEFAULT_HEIGHT));
    [HearderView shareInstance].startButton.frame = CGRectMake(_WIDTH - 160 * (_WIDTH / _DEFAULT_WIDTH), 15, 30 * (_WIDTH / _DEFAULT_WIDTH), 30 * (_HEIGHT / _DEFAULT_HEIGHT));
    [HearderView shareInstance].nextButton.frame = CGRectMake(_WIDTH - 80 * (_WIDTH / _DEFAULT_WIDTH), 15, 30 * (_WIDTH / _DEFAULT_WIDTH), 30 * (_HEIGHT / _DEFAULT_HEIGHT));
    
    [HearderView shareInstance].progressSlider.alpha = 0;
    [HearderView shareInstance].likeBtn.alpha = 0;
    [HearderView shareInstance].downloadBtn.alpha = 0;
    
}

- (void)initMainView
{
    _classListTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 74 * (_HEIGHT / _DEFAULT_HEIGHT), _WIDTH, _HEIGHT - 138 * (_HEIGHT / _DEFAULT_HEIGHT)) style:UITableViewStylePlain];
    [self.view addSubview:_classListTableView];
    _classListTableView.tag = 1;
    _classListTableView.delegate = self;
    _classListTableView.dataSource = self;
    _classListTableView.showsVerticalScrollIndicator = NO;
    _classListTableView.backgroundColor = [UIColor clearColor];
    _classListTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    _catalogTableView = [[UITableView alloc] initWithFrame:CGRectMake(- 150, 30, 150, _HEIGHT - 94) style:UITableViewStylePlain];
    _catalogTableView.backgroundColor = [UIColor blackColor];
    _catalogTableView.alpha = 0.8;
    _catalogTableView.delegate = self;
    _catalogTableView.dataSource = self;
    _catalogTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_catalogTableView];
    [self.view sendSubviewToBack:_catalogTableView];
    [self.view bringSubviewToFront:_button];
    [self.view bringSubviewToFront:_backgroundView];
    [self.view bringSubviewToFront:_hearderView];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 1) {
        static NSString *identifier = @"cell";
        ClassListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[ClassListTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        Tag_typeModel *tab_typeModel = [_arrayData objectAtIndex:indexPath.section];
        ClassListModel *classListModel = [tab_typeModel.arrayData objectAtIndex:indexPath.row];
        [cell setClassListModel:classListModel];
        _imageNumber = 0;
        for (int i = 0; i < indexPath.section; i++) {
            Tag_typeModel *tab_typeModel = [_arrayData objectAtIndex:indexPath.section];
            _imageNumber += tab_typeModel.arrayData.count;
        }
        _imageNumber += indexPath.row + 6;
        NSString *imageUrl = [_imageArray objectAtIndex:_imageNumber];
        [cell.bgImageView setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"bgImage3"]];
        cell.bgImageView.contentMode = UIViewContentModeScaleAspectFill;
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
        
    }
    static NSString *identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    Tag_typeModel *tab_typeModel = [_arrayData objectAtIndex:indexPath.section];
    ClassListModel *classListModel = [tab_typeModel.arrayData objectAtIndex:indexPath.row];
    cell.textLabel.text = [NSString stringWithFormat:@"o    %@", classListModel.tag_name];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.backgroundColor = [UIColor blackColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(20, 35, 1, 15)];
    view.backgroundColor = [UIColor whiteColor];
    [cell addSubview:view];
    
    
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    Tag_typeModel *model = [_arrayData objectAtIndex:section];
    return model.arrayData.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _arrayData.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (tableView.tag == 1) {
        return 40;
    } else {
        return 30;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (tableView.tag == 1) {
        UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
        UIVisualEffectView *backgroundView = [[UIVisualEffectView alloc] initWithEffect:effect];
        backgroundView.frame = CGRectMake(0, 0, _WIDTH, 40);
        
        UIImageView *HeadImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _WIDTH, 40)];
        [HeadImageView addSubview:backgroundView];
        [HeadImageView setImage:[UIImage imageNamed:@"biaotilan"]];
        UIImageView *iconView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 5, 30, 30)];
        //    HeadImageView.backgroundColor = [UIColor colorWithRed:149 / 255.0 green:207 / 255.0 blue:243 / 255.0 alpha:1];
        [iconView setImage:[UIImage imageNamed:@"iconfont-zhiweileibie"]];
        UILabel *headLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, _WIDTH - 60, 40)];
        Tag_typeModel *model = [_arrayData objectAtIndex:section];
        headLabel.text = model.tag_type_name;
        headLabel.backgroundColor = [UIColor clearColor];
        headLabel.font = [UIFont systemFontOfSize:24];
        [HeadImageView addSubview:iconView];
        [HeadImageView addSubview:headLabel];
        return HeadImageView;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 1) {
        return 150;
    }
    return 40;
}

- (void)tap
{
    [[CDSideBarController sharedInstance] dismissMenu];
    [UIView animateWithDuration:0.8 animations:^{
        self.singerListView.frame = CGRectMake(-(_WIDTH - 20), 150 * (_HEIGHT / _DEFAULT_HEIGHT), _WIDTH - 20, _HEIGHT - 300 * (_HEIGHT / _DEFAULT_HEIGHT));
        _backgroundView.alpha = 0.0;
        _catalogTableView.frame = CGRectMake(-120, 30, 120, _HEIGHT - 94);
        _button.frame = CGRectMake(10, _HEIGHT - 130 * (_HEIGHT / _DEFAULT_HEIGHT), 40, 40);
    }];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [[CDSideBarController sharedInstance] dismissMenu];
    if (tableView.tag == 1) {
        Tag_typeModel *model = [_arrayData objectAtIndex:indexPath.section];
        ClassListModel *classListModel = [model.arrayData objectAtIndex:indexPath.row];
        [UIView animateWithDuration:0.8 animations:^{
            _singerListView.frame = CGRectMake(0, 150 * (_HEIGHT / _DEFAULT_HEIGHT), _WIDTH - 20, _HEIGHT - 300 * (_HEIGHT / _DEFAULT_HEIGHT));
            _backgroundView.alpha = 0.7;
        }];
        
        RankMusicList *rangkMusicList = [[RankMusicList alloc] initWithFrame:CGRectMake(0, 40 * (_HEIGHT / _DEFAULT_HEIGHT), _WIDTH - 20, _HEIGHT - 350 * (_HEIGHT / _DEFAULT_HEIGHT)) selectId:classListModel.tag_id isRank:NO];
        rangkMusicList.touchTableViewDelegate = self;
        rangkMusicList.backgroundColor = [UIColor clearColor];
        
        for (UIView *view in self.singerListView.subviews) {
            [view removeFromSuperview];
        }
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, self.singerListView.frame.size.width - 10, 40 * (_HEIGHT / _DEFAULT_HEIGHT))];
        self.titleLabel.textColor = [UIColor blackColor];
        [self.singerListView addSubview:self.titleLabel];
        [self.singerListView addSubview:rangkMusicList];
        self.titleLabel.text = classListModel.tag_name;
        
        
        [UIView animateWithDuration:0.8 animations:^{
            self.singerListView.frame = CGRectMake(0, 150 * (_HEIGHT / _DEFAULT_HEIGHT), _WIDTH - 20, _HEIGHT - 300 * (_HEIGHT / _DEFAULT_HEIGHT));
            _backgroundView.alpha = 0.7;
        }];
        [self.view bringSubviewToFront:_backgroundView];
        [self.view bringSubviewToFront:self.singerListView];
        [self.view bringSubviewToFront:_hearderView];
    } else {
        [UIView animateWithDuration:0.8 animations:^{
            _backgroundView.alpha = 0.0;
            _catalogTableView.frame = CGRectMake(-120, 30, 120, _HEIGHT - 94);
            _button.frame = CGRectMake(10, _HEIGHT - 130 * (_HEIGHT / _DEFAULT_HEIGHT), 40, 40);
        }];
        [_classListTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
    }
}


// SingerMusicList 代理方法

- (void)sendTableViewTouchEnd
{
    if (self.currentX < 0 && self.singerListView.frame.origin.x != 0) {
        [UIView animateWithDuration:0.8 animations:^{
            self.singerListView.frame = CGRectMake(-(_WIDTH - 20), 150 * (_HEIGHT / _DEFAULT_HEIGHT), _WIDTH - 20, _HEIGHT - 300 * (_HEIGHT / _DEFAULT_HEIGHT));
            _backgroundView.alpha = 0.0;
        }];
    } else if (self.currentX >= 0 && self.singerListView.frame.origin.x != 0) {
        [UIView animateWithDuration:0.8 animations:^{
            self.singerListView.frame = CGRectMake(0, 150 * (_HEIGHT / _DEFAULT_HEIGHT), _WIDTH - 20, _HEIGHT - 300 * (_HEIGHT / _DEFAULT_HEIGHT));
            _backgroundView.alpha = 0.7;
        }];
    }
    
    
    
    _totalDistance = 0;
    self.currentX = 0;
}

- (void)getTableViewTouch:(CGFloat)pointX
{
    self.currentX = 0;
    _totalDistance += pointX;
    if (pointX < -5 || pointX > 5) {
        self.currentX = pointX;
    }
    if (self.singerListView.frame.origin.x + pointX <= 0 && -_totalDistance < (_WIDTH - 30 * (_WIDTH / _DEFAULT_WIDTH))) {
        self.singerListView.center = CGPointMake(self.singerListView.center.x + self.currentX, self.singerListView.center.y);
        if (_totalDistance < 0) {
            _backgroundView.alpha = 0.5 - 0.5 * (-_totalDistance / (_WIDTH - 30 * (_WIDTH / _DEFAULT_WIDTH)));
        } else if (_totalDistance < (_WIDTH - 30 * (_WIDTH / _DEFAULT_WIDTH))) {
            _backgroundView.alpha = 0.5 * (_totalDistance / (_WIDTH - 30 * (_WIDTH / _DEFAULT_WIDTH)));
        }
    }
}

- (void)goBackTableView:(NSString *)SingerName number:(NSInteger)number
{
    [MusicPlayer1 shareInstance].isDownLoad = NO;
    [MusicPlayer1 shareInstance].isDownLoadList = NO;
    [[CDSideBarController sharedInstance] dismissMenu];
    MusicModel *model = [[MusicPlayer1 shareInstance].list objectAtIndex:number];
    [MusicPlayer1 shareInstance].firstPlay = YES;
    [MusicPlayer1 shareInstance].currentMusic = number;
    [[MusicPlayer1 shareInstance].moviePlayer setContentURL:[NSURL URLWithString:model.url]];
    [MusicPlayer1 shareInstance].isPlay = YES;
    [[HearderView shareInstance].startButton setImage:[UIImage imageNamed:@"pause"] forState:UIControlStateNormal];
    [[MusicPlayer1 shareInstance] play];
    [[HearderView shareInstance].listTableView reloadData];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
